package com.woniuxy.controller;

import com.woniuxy.controller.entity.User;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 马宇航
 * @Todo: TODO
 * @DateTime: 22/01/25/0025 下午 4:30
 * @Component: 成都蜗牛学苑
 **/
@RestController //通常是用于restful风格写法的
public class UserRestFulController {
    /**
    * @Author: 马宇航
    * @Todo: post提交json对象的restful风格！还能额外添加新的参数 /user/{id}/{userid}/{myname}
    * @DateTime:  22/01/25/0025 下午 4:45
    * @Component: 成都蜗牛学苑
    **/
    @RequestMapping(value = "/user",method = RequestMethod.POST)
    public String addUser(@RequestBody User user){
        System.out.println("UserRestFulController.addUser方法执行！");
        return user.toString();
    }
    /**
     * @Todo: rest风格传参 1个 2个
     * ChangeLog : 1. 创建 (22/01/25/0025 下午 4:33 [马宇航]);
     * @param id
     * @return java.lang.String
    */
    @DeleteMapping("/user/{id}/{userid}/{myname}")
    public String deleteUser(@PathVariable("userid") int id,@PathVariable("id") int userid,@PathVariable String myname){
        System.out.println("UserRestFulController.deleteUser执行");
        return id+"--"+userid+"---"+myname;
    }
    /**
     * @Todo: rest风格传参 1个 2个
     * ChangeLog : 1. 创建 (22/01/25/0025 下午 4:33 [马宇航]);
     * @param id
     * @return java.lang.String
     */
    @DeleteMapping("/user/{id}/{myname}")
    public String deleteUser(@PathVariable("id") int id,@PathVariable String myname){
        System.out.println("UserRestFulController.deleteUser执行");
        return id+"--"+"---"+myname;
    }
    @PutMapping("/user")
    public String updateUser(@RequestBody User user){
        System.out.println("UserRestFulController.updateUser执行");
        return user.toString();
    }
    @GetMapping("/user/{id}")
    public String findUser(@PathVariable("id") int userid){
        System.out.println("UserRestFulController.findUser执行："+userid);
        User user = new User(userid+"",userid);
        return user.toString();
    }
}
